package com.example.activitytest;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	int a = 0;
	int b = 0;
	private Button addA;
	private Button addB;
	private TextView showA;
	private TextView showB;
	private static final int ATCIVITY_EDIT = 1;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		showA = (TextView)findViewById(R.id.showA);
		showB = (TextView)findViewById(R.id.showB);
		
		addA = (Button)findViewById(R.id.addA);
		addB = (Button)findViewById(R.id.addB);
		
		showA.setText(Integer.toString(a));
		showB.setText(Integer.toString(b));
		
		addA.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, ChildActivity.class);
				Bundle bundle = new Bundle();
				bundle.putInt("VAL_OF_A", a);
				intent.putExtras(bundle);
				startActivityForResult(intent, ATCIVITY_EDIT);
			}
		});
		addB.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				b++;
				showB.setText(Integer.toString(b));
			}
		});
	
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        	Bundle bundle = data.getExtras();
        	Log.d("MainActivity", "hahaha bundle"+bundle);
        	Log.d("MainActivity", "hahaha bundle"+bundle.getInt("VAL_OF_A_C"));
        	a = bundle.getInt("VAL_OF_A_C");
        	showA.setText(Integer.toString(a));
        /*if (requestCode==REQUEST_CODE){
            if(resultCode==RESULT_CANCELED)
                  setTitle("cancle");
            else if (resultCode==RESULT_OK) {
                 String temp=null;
                 Bundle bundle=data.getExtras();
                 if(bundle!=null)   temp=bundle.getString("ID");
                 setTitle(temp);
            }
        }*/
    }
	
}
